package cnu.ldc.service;



import cnu.ldc.dao.UserJdbcDaoImpl;
import cnu.ldc.dao.iface.UserDao;
import cnu.ldc.db.util.TransactionManager;
import cnu.ldc.doman.User;
import cnu.ldc.doman.UserDetail;
import cnu.ldc.service.iface.Userservice;


public class UserserviceImpl implements Userservice {
	private UserDao userdao=new UserJdbcDaoImpl();
	@Override
	public boolean login(String name, String password) {
	
		 boolean flog=false;
				 if(userdao.checkUser(name, password)==1) {
					 flog=true;
				 };
		 return flog;
		
	}
	@Override
	public boolean register(User user, UserDetail ud) {
		boolean flag=false;
		TransactionManager tm=new TransactionManager();
		tm.beginTranscation();
			int userId=userdao.insertUser(user);
			ud.setUserId(userId);
			int rowNum=userdao.insertUserDetail(ud);
		tm.commitAndClose();
		if(userId!=-1&&rowNum!=0) {
			flag=true;
		}
		return flag;
	}

}
